********************************************************************************
* load inheritance data
u $data/inheritance_event, replace
rename lnr_giv lnr
merge m:1 lnr year using $data/welfare_9319.dta, keep(match master) nogen keepusing(hhid nt_stocks_PB_a nt_mfund_a nt_stocks_a nt_equity_PB_a nt_housing_PB_a capita)
rename lnr lnr_giv
rename hhid hhid_giv
rename capita capita_giv
rename lnr_rec lnr
merge m:1 lnr year using $data/welfare_9319.dta, keep(match master) nogen keepusing(hhid capita)
rename lnr lnr_rec
rename hhid hhid_rec
rename capita capita_rec
keep if hhid_rec != . & hhid_giv != .
duplicates drop
bys hhid_giv: gen share = 1/_N

foreach var in stocks_PB housing_PB equity_PB stocks mfund {
	replace nt_`var'_a = 0 if nt_`var'_a == .
	gen nt_`var'_a_rec = nt_`var'_a*capita_giv*share
}

* make one database for recipients and one for senders

* 1 senders: 
preserve
bys hhid_giv year: keep if _n == 1
gen beq_event = 1
keep lnr_giv hhid_giv year beq_event
rename lnr_giv lnr 
rename hhid_giv hhid
save $data/apr_bequest_give_event.dta, replace
restore

* 2 recipients
collapse (sum) nt_*_rec (max) lnr_rec, by(hhid_rec year)
keep lnr_rec hhid_rec year nt_*_rec
rename lnr_rec lnr 
rename hhid_rec hhid
save $data/apr_bequest_rec_event.dta, replace


